#!/bin/bash


files=$(ls *.sql)   # 文件列表
target="./db_encode.go"  # 生成的目标go文件
package="database"  # 当前库名
package=$(pwd)
package=${package##*/}  # 自动从当前目录获取

#################################
content=""
farr=""
for f in ${files}
do
  echo ${f}
#  s=$(base64 -w 0 <<<"$(cat ${f})")
  s=$(base64 -i ${f})
  content="${content}
  \"${f}\":decode(\`${s}\`),"
  farr="${farr}
  \"${f}\","
done

echo "==== done" ${target}
now=$(date -R)

cat>"${target}"<<EOF
package ${package}
// auto general at: ${now}
import (
	"encoding/base64"
)

func decode(s string) string {
	decoded, _ := base64.StdEncoding.DecodeString(s)
	return string(decoded)
}

var DbVersionSql=map[string]string{
  ${content}
}

var DbVersions=[]string{
  ${farr}
}
EOF

#cat ${target}